class Course {
  Course({
    this.audiences,
    this.backPicture,
    this.buyNum,
    this.chapters,
    this.coverLong,
    this.coverSquare,
    this.createdAt,
    this.difficulty,
    this.favoriteNum,
    this.goals,
    this.isRecommended,
    this.isStick,
    this.isVip,
    this.learnNum,
    this.length,
    this.lessonNum,
    this.lessonNumberPublish,
    this.marketing,
    this.mbIntroduceContent,
    this.pcIntroduceBack,
    this.pcIntroduceCode,
    this.pcIntroduceContent,
    this.pcIntroduceType,
    this.rating,
    this.ratingCount,
    this.ratingLogic,
    this.ratingPopular,
    this.ratingPractical,
    this.ratingStatus,
    this.serializeMode,
    this.status,
    this.subtitle,
    this.summary,
    this.title,
    this.type,
    this.updatedAt,
    this.userCourseLearn,
    this.uuid,
  });

  ///适合人群
  String? audiences;

  ///背景图
  String? backPicture;

  ///购买人数
  int? buyNum;
  List<CourseChapter?>? chapters;

  ///封面图大图
  String? coverLong;

  ///封面图小图
  String? coverSquare;

  ///创建时间
  String? createdAt;

  ///难度，0:零基础,1:初阶,2:进阶,3:高阶
  String? difficulty;

  ///收藏人数
  int? favoriteNum;

  ///课程目标
  String? goals;

  ///是否推荐
  int? isRecommended;

  ///置顶
  bool? isStick;

  ///是否会员
  int? isVip;

  ///虚拟人数
  int? learnNum;

  ///课程时长
  int? length;

  ///课时总数
  int? lessonNum;

  ///课时发布数
  int? lessonNumberPublish;
  Marketing? marketing;

  ///移动端介绍内容
  String? mbIntroduceContent;

  ///电脑端介绍背景图
  String? pcIntroduceBack;

  ///电脑端介绍代码，css:css代码,html:html代码,js:JS代码
  List<String>? pcIntroduceCode;

  ///电脑端介绍内容
  String? pcIntroduceContent;

  ///电脑端介绍形式，text:富文本,code:代码形式
  String? pcIntroduceType;

  ///评分
  int? rating;

  ///评价数量
  int? ratingCount;

  ///通俗易懂评分
  int? ratingLogic;

  ///通俗易懂评分
  int? ratingPopular;

  ///内容使用评分
  int? ratingPractical;

  ///评价状态，all:允许任何人评论,filter:筛选后显示,closed:关闭评论
  String? ratingStatus;

  ///连载状，none:非连载课程,serialize:更新中,finished:已完结
  String? serializeMode;

  ///状态，created:草稿, published:已发布, unpublished:未发布,cancelled:作废,closed:删除
  String? status;

  ///副标题
  String? subtitle;

  ///简介
  String? summary;

  ///标题
  String? title;

  ///课程类型，course:课程,training:训练营课程
  String? type;

  ///更新时间
  String? updatedAt;

  ///用户课程情况，study_started_at为空则为该课程未学习
  UserHasCourse? userCourseLearn;

  ///UUID
  String? uuid;

  factory Course.fromJson(Map<String, dynamic> json) => Course(
        audiences: json["audiences"],
        backPicture: json["back_picture"],
        buyNum: json["buy_num"],
        chapters: List<CourseChapter>.from(
            json["chapters"] ?? [].map((x) => CourseChapter.fromJson(x))),
        coverLong: json["cover_long"],
        coverSquare: json["cover_square"],
        createdAt: json["created_at"],
        difficulty: json["difficulty"],
        favoriteNum: json["favorite_num"],
        goals: json["goals"],
        isRecommended: json["is_recommended"],
        isStick: json["is_stick"],
        isVip: json["is_vip"],
        learnNum: json["learn_num"],
        length: json["length"],
        lessonNum: json["lesson_num"],
        lessonNumberPublish: json["lesson_number_publish"],
        marketing: json["marketing"],
        mbIntroduceContent: json["mb_introduce_content"],
        pcIntroduceBack: json["pc_introduce_back"],
        pcIntroduceCode:
            List<String>.from(json["pc_introduce_code"] ?? [].map((x) => x)),
        pcIntroduceContent: json["pc_introduce_content"],
        pcIntroduceType: json["pc_introduce_type"],
        rating: json["rating"],
        ratingCount: json["rating_count"],
        ratingLogic: json["rating_logic"],
        ratingPopular: json["rating_popular"],
        ratingPractical: json["rating_practical"],
        ratingStatus: json["rating_status"],
        serializeMode: json["serialize_mode"],
        status: json["status"],
        subtitle: json["subtitle"],
        summary: json["summary"],
        title: json["title"],
        type: json["type"],
        updatedAt: json["updated_at"],
        userCourseLearn: UserHasCourse.fromJson(json["user_course_learn"]),
        uuid: json["uuid"],
      );

  Map<String, dynamic> toJson() => {
        "audiences": audiences,
        "back_picture": backPicture,
        "buy_num": buyNum,
        "chapters": List<dynamic>.from(chapters ?? [].map((x) => x?.toJson())),
        "cover_long": coverLong,
        "cover_square": coverSquare,
        "created_at": createdAt,
        "difficulty": difficulty,
        "favorite_num": favoriteNum,
        "goals": goals,
        "is_recommended": isRecommended,
        "is_stick": isStick,
        "is_vip": isVip,
        "learn_num": learnNum,
        "length": length,
        "lesson_num": lessonNum,
        "lesson_number_publish": lessonNumberPublish,
        "marketing": marketing,
        "mb_introduce_content": mbIntroduceContent,
        "pc_introduce_back": pcIntroduceBack,
        "pc_introduce_code":
            List<dynamic>.from(pcIntroduceCode ?? [].map((x) => x)),
        "pc_introduce_content": pcIntroduceContent,
        "pc_introduce_type": pcIntroduceType,
        "rating": rating,
        "rating_count": ratingCount,
        "rating_logic": ratingLogic,
        "rating_popular": ratingPopular,
        "rating_practical": ratingPractical,
        "rating_status": ratingStatus,
        "serialize_mode": serializeMode,
        "status": status,
        "subtitle": subtitle,
        "summary": summary,
        "title": title,
        "type": type,
        "updated_at": updatedAt,
        "user_course_learn": userCourseLearn?.toJson(),
        "uuid": uuid,
      };
}

class CourseChapter {
  CourseChapter({
    this.courseId,
    this.createdAt,
    this.description,
    this.lesson,
    this.lessonNumber,
    this.lessonNumberPublish,
    this.number,
    this.numberPath,
    this.parts,
    this.status,
    this.title,
    this.type,
    this.updatedAt,
    this.uuid,
  });

  ///课程ID
  int? courseId;

  ///创建时间
  String? createdAt;

  ///描述
  String? description;
  Lesson? lesson;

  ///课时总数
  int? lessonNumber;

  ///课时发布数
  int? lessonNumberPublish;

  ///序号
  int? number;

  ///序号路径
  String? numberPath;
  List<PartElement>? parts;

  ///状态，created:草稿, published:已发布, unpublished:未发布,cancelled:作废,closed:删除
  String? status;

  ///标题
  String? title;

  ///类型，chapter:章,lesson:课时
  String? type;

  ///更新时间
  String? updatedAt;

  ///UUID
  String? uuid;

  factory CourseChapter.fromJson(Map<String, dynamic> json) => CourseChapter(
        courseId: json["course_id"],
        createdAt: json["created_at"],
        description: json["description"],
        lesson: Lesson.fromJson(json["lesson"]),
        lessonNumber: json["lesson_number"],
        lessonNumberPublish: json["lesson_number_publish"],
        number: json["number"],
        numberPath: json["number_path"],
        parts: List<PartElement>.from(
            json["parts"] ?? [].map((x) => PartElement.fromJson(x))),
        status: json["status"],
        title: json["title"],
        type: json["type"],
        updatedAt: json["updated_at"],
        uuid: json["uuid"],
      );

  Map<String, dynamic> toJson() => {
        "course_id": courseId,
        "created_at": createdAt,
        "description": description,
        "lesson": lesson?.toJson(),
        "lesson_number": lessonNumber,
        "lesson_number_publish": lessonNumberPublish,
        "number": number,
        "number_path": numberPath,
        "parts": List<dynamic>.from(parts ?? [].map((x) => x?.toJson())),
        "status": status,
        "title": title,
        "type": type,
        "updated_at": updatedAt,
        "uuid": uuid,
      };
}

///lesson
class Lesson {
  Lesson({
    this.content,
    this.createdAt,
    this.finishDetail,
    this.finishType,
    this.isFree,
    this.length,
    this.number,
    this.path,
    this.reminds,
    this.source,
    this.status,
    this.title,
    this.type,
    this.updatedAt,
    this.userLearn,
    this.uuid,
  });

  ///正文，文稿和图文
  String? content;

  ///创建时间
  String? createdAt;

  ///完成条件
  String? finishDetail;

  ///完成类型
  String? finishType;

  ///是否试听，0:否,1:是
  bool? isFree;

  ///长度，若是视频类型，则表示时长；若是ppt，则表示页数；由具体的活动业务来定义
  int? length;

  ///序号
  int? number;

  ///路径
  String? path;

  ///课时上课提醒
  Reminds? reminds;

  ///来源，not:无, aliyun:阿里云, tencent:腾讯云
  String? source;

  ///状态，created:草稿, published:已发布, unpublished:未发布,cancelled:作废,closed:删除
  String? status;

  ///标题
  String? title;

  ///类型，video:视频,pdf:PDF text:图文,roll:作业
  String? type;

  ///更新时间
  String? updatedAt;

  ///课时学习记录
  UserLearn? userLearn;

  ///UUID
  String? uuid;

  factory Lesson.fromJson(Map<String, dynamic> json) => Lesson(
        content: json["content"],
        createdAt: json["created_at"],
        finishDetail: json["finish_detail"],
        finishType: json["finish_type"],
        isFree: json["is_free"],
        length: json["length"],
        number: json["number"],
        path: json["path"],
        reminds: Reminds.fromJson(json["reminds"]),
        source: json["source"],
        status: json["status"],
        title: json["title"],
        type: json["type"],
        updatedAt: json["updated_at"],
        userLearn: UserLearn.fromJson(json["user_learn"]),
        uuid: json["uuid"],
      );

  Map<String, dynamic> toJson() => {
        "content": content,
        "created_at": createdAt,
        "finish_detail": finishDetail,
        "finish_type": finishType,
        "is_free": isFree,
        "length": length,
        "number": number,
        "path": path,
        "reminds": reminds?.toJson(),
        "source": source,
        "status": status,
        "title": title,
        "type": type,
        "updated_at": updatedAt,
        "user_learn": userLearn?.toJson(),
        "uuid": uuid,
      };
}

///课时上课提醒
class Reminds {
  Reminds({
    this.attendedAt,
    this.isExpire,
  });

  ///上课时间
  String? attendedAt;

  ///是否到期
  bool? isExpire;

  factory Reminds.fromJson(Map<String, dynamic> json) => Reminds(
        attendedAt: json["attended_at"],
        isExpire: json["is_expire"],
      );

  Map<String, dynamic> toJson() => {
        "attended_at": attendedAt,
        "is_expire": isExpire,
      };
}

///课时学习记录
///
///user_learn
class UserLearn {
  UserLearn({
    this.createdAt,
    this.finishAt,
    this.lastViewedPosition,
    this.lastWatchLength,
    this.lessonLength,
    this.schedule,
    this.startAt,
    this.status,
    this.updatedAt,
    this.uuid,
    this.watchDuration,
    this.watchDurationMax,
    this.watchNum,
  });

  ///创建时间
  String? createdAt;

  ///学习完成时间
  String? finishAt;

  ///上次观看位置
  int? lastViewedPosition;

  ///上次观看时长
  int? lastWatchLength;

  ///学习时长
  String? lessonLength;

  ///学习进度
  int? schedule;

  ///开始时间
  String? startAt;

  ///状态，[learning:学习, finished:完成]
  String? status;

  ///更新时间
  String? updatedAt;

  ///UUID
  String? uuid;

  ///观看时长
  int? watchDuration;

  ///观看最大时长
  int? watchDurationMax;

  ///观看次数
  int? watchNum;

  factory UserLearn.fromJson(Map<String, dynamic> json) => UserLearn(
        createdAt: json["created_at"],
        finishAt: json["finish_at"],
        lastViewedPosition: json["last_viewed_position"],
        lastWatchLength: json["last_watch_length"],
        lessonLength: json["lesson_length"],
        schedule: json["schedule"],
        startAt: json["start_at"],
        status: json["status"],
        updatedAt: json["updated_at"],
        uuid: json["uuid"],
        watchDuration: json["watch_duration"],
        watchDurationMax: json["watch_duration_max"],
        watchNum: json["watch_num"],
      );

  Map<String, dynamic> toJson() => {
        "created_at": createdAt,
        "finish_at": finishAt,
        "last_viewed_position": lastViewedPosition,
        "last_watch_length": lastWatchLength,
        "lesson_length": lessonLength,
        "schedule": schedule,
        "start_at": startAt,
        "status": status,
        "updated_at": updatedAt,
        "uuid": uuid,
        "watch_duration": watchDuration,
        "watch_duration_max": watchDurationMax,
        "watch_num": watchNum,
      };
}

///chapter
class PartElement {
  PartElement({
    this.courseId,
    this.createdAt,
    this.description,
    this.lesson,
    this.lessonNumber,
    this.lessonNumberPublish,
    this.number,
    this.numberPath,
    this.status,
    this.title,
    this.type,
    this.updatedAt,
    this.uuid,
  });

  ///课程ID
  int? courseId;

  ///创建时间
  String? createdAt;

  ///描述
  String? description;
  Lesson? lesson;

  ///课时总数
  int? lessonNumber;

  ///课时发布数
  int? lessonNumberPublish;

  ///序号
  int? number;

  ///序号路径
  String? numberPath;

  ///状态，created:草稿, published:已发布, unpublished:未发布,cancelled:作废,closed:删除
  String? status;

  ///标题
  String? title;

  ///类型，chapter:章,lesson:课时
  String? type;

  ///更新时间
  String? updatedAt;

  ///UUID
  String? uuid;

  factory PartElement.fromJson(Map<String, dynamic> json) => PartElement(
        courseId: json["course_id"],
        createdAt: json["created_at"],
        description: json["description"],
        lesson: Lesson.fromJson(json["lesson"]),
        lessonNumber: json["lesson_number"],
        lessonNumberPublish: json["lesson_number_publish"],
        number: json["number"],
        numberPath: json["number_path"],
        status: json["status"],
        title: json["title"],
        type: json["type"],
        updatedAt: json["updated_at"],
        uuid: json["uuid"],
      );

  Map<String, dynamic> toJson() => {
        "course_id": courseId,
        "created_at": createdAt,
        "description": description,
        "lesson": lesson?.toJson(),
        "lesson_number": lessonNumber,
        "lesson_number_publish": lessonNumberPublish,
        "number": number,
        "number_path": numberPath,
        "status": status,
        "title": title,
        "type": type,
        "updated_at": updatedAt,
        "uuid": uuid,
      };
}

class Marketing {
  Marketing({
    this.companyId,
    this.discount,
    this.discountEndAt,
    this.invoiceGoods,
    this.price,
    this.uuid,
  });

  ///公司ID
  int? companyId;

  ///折扣价格
  int? discount;

  ///折扣结束时间
  String? discountEndAt;

  ///发票开票内容ID
  List<dynamic>? invoiceGoods;

  ///价格
  int? price;

  ///UUID
  String? uuid;

  factory Marketing.fromJson(Map<String, dynamic> json) => Marketing(
        companyId: json["company_id"],
        discount: json["discount"],
        discountEndAt: json["discount_end_at"],
        invoiceGoods:
            List<dynamic>.from(json["invoice_goods"] ?? [].map((x) => x)),
        price: json["price"],
        uuid: json["uuid"],
      );

  Map<String, dynamic> toJson() => {
        "company_id": companyId,
        "discount": discount,
        "discount_end_at": discountEndAt,
        "invoice_goods": List<dynamic>.from(invoiceGoods ?? [].map((x) => x)),
        "price": price,
        "uuid": uuid,
      };
}

///用户课程情况，study_started_at为空则为该课程未学习
///
///user_has_course
class UserHasCourse {
  UserHasCourse({
    this.chapter,
    this.createdAt,
    this.expiredAt,
    this.finishedAt,
    this.lastLearnAt,
    this.lastViewedAt,
    this.lesson,
    this.lessonType,
    this.schedule,
    this.startAt,
    this.studyStartedAt,
    this.updatedAt,
    this.uuid,
    this.watchDuration,
    this.watchDurationMax,
  });

  PartElement? chapter;

  ///创建时间
  String? createdAt;

  ///到期时间
  String? expiredAt;

  ///学习完成时间
  String? finishedAt;

  ///最后学习时间
  String? lastLearnAt;

  ///学习结束时间
  String? lastViewedAt;
  Lesson? lesson;

  ///上次学习的课时类型[video:视频, pdf:PDF,text:图文]
  String? lessonType;

  ///学习进度
  int? schedule;

  ///开始时间
  String? startAt;

  ///学习开始时间
  String? studyStartedAt;

  ///更新时间
  String? updatedAt;

  ///UUID
  String? uuid;

  ///累积观看时长
  int? watchDuration;

  ///累积观看最大时长
  int? watchDurationMax;

  factory UserHasCourse.fromJson(Map<String, dynamic> json) => UserHasCourse(
        chapter: PartElement.fromJson(json["chapter"]),
        createdAt: json["created_at"],
        expiredAt: json["expired_at"],
        finishedAt: json["finished_at"],
        lastLearnAt: json["last_learn_at"],
        lastViewedAt: json["last_viewed_at"],
        lesson: Lesson.fromJson(json["lesson"]),
        lessonType: json["lesson_type"],
        schedule: json["schedule"],
        startAt: json["start_at"],
        studyStartedAt: json["study_started_at"],
        updatedAt: json["updated_at"],
        uuid: json["uuid"],
        watchDuration: json["watch_duration"],
        watchDurationMax: json["watch_duration_max"],
      );

  Map<String, dynamic> toJson() => {
        "chapter": chapter?.toJson(),
        "created_at": createdAt,
        "expired_at": expiredAt,
        "finished_at": finishedAt,
        "last_learn_at": lastLearnAt,
        "last_viewed_at": lastViewedAt,
        "lesson": lesson?.toJson(),
        "lesson_type": lessonType,
        "schedule": schedule,
        "start_at": startAt,
        "study_started_at": studyStartedAt,
        "updated_at": updatedAt,
        "uuid": uuid,
        "watch_duration": watchDuration,
        "watch_duration_max": watchDurationMax,
      };
}
